<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通达快递 TDCargo-通行天下,使命必达</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-fluid" style="padding: 15px;">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                <form id="usr-sender-list-query-form" class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input name="senderName" type="text" class="layui-input"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button id="usr-sender-list-query-btn" class="layui-btn" lay-submit
                                    lay-filter="usr-sender-list-query-submit">查询
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

            <table class="layui-hide" id="usr-sender-list-table" lay-filter="usr-sender-list-table"></table>
        </div>
    </div>
</div>

<script type="text/html" id="usr-sender-table-tpl">
    <a class="layui-btn layui-btn-xs" lay-event="choose">选择</a>
</script>

<script src="/layui/layui.js"></script>
<script>
    layui.config({
        base: '/src/',
        version: new Date().getTime()
    }).extend({setter: "config", admin: "lib/admin", view: "lib/view"})
        .define(['setter', 'admin', 'table', "form"], function () {
            var $ = layui.$,
                admin = layui.admin,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#usr-sender-list-table',
                url: '/usr/listUsrSender',
                cols: [[
                    {field: 'id', title: 'ID', width: 80},
                    {field: 'name', title: '姓名'},
                    {field: 'telphone', title: '电话'},
                    {field: 'addr', title: '地址'},
                    {field: 'postcode', title: '邮编'},
                    {title: '操作', width: 80, templet: "#usr-sender-table-tpl"}
                ]],
                where: {
                    access_token: layui.data('layuiAdmin').access_token
                }
            });

            table.on("tool(usr-sender-list-table)", function (obj) {
                if (obj.event === "choose") {
                    var data = obj.data;
                    if (parent.layui.$("#bil-express-add-form input[name=senderTelphone]").length !== 0) {
                        parent.layui.$("#bil-express-add-form input[name=senderName]").val(data.name);
                        parent.layui.$("#bil-express-add-form input[name=senderTelphone]").val(data.telphone);
                        parent.layui.$("#bil-express-add-form input[name=senderAddr]").val(data.addr);
                    } else if (parent.layui.$("#bil-express-edit-form input[name=senderTelphone]").length !== 0) {
                        parent.layui.$("#bil-express-edit-form input[name=senderName]").val(data.name);
                        parent.layui.$("#bil-express-edit-form input[name=senderTelphone]").val(data.telphone);
                        parent.layui.$("#bil-express-edit-form input[name=senderAddr]").val(data.addr);
                    }
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });

            form.on("submit(usr-sender-list-query-submit)", function (obj) {
                layer.load(2, {time: 100 * 1000});

                var data = obj.field;
                data["access_token"] = layui.data('layuiAdmin').access_token;

                table.reload("usr-sender-list-table", {
                    where: data,
                    done: function () {
                        layer.closeAll('loading');
                    }
                });

                return false;
            });
        });
</script>
</body>
</html>